﻿using System;
using System.Threading;
using D3;
using D3.Pathing;
using NYTBD;
using NYTBD.Common;



namespace NYTBD.Modules
{
    internal static class Squanto
    {

        public const int MaxStepsDefault = 20;
        public const float MinDistDefault = 10f;

        public static void Init()
        {

        }


        public static int WalkAtomic(float x, float y, uint count = 0, float mindist = MinDistDefault)
        {

            /*if (count >= MaxStepsDefault) return -1;

            if (GetDistance(Me.X, Me.Y, x, y) < mindist)
            {
                return 0;
            }*/

            Me.UsePower(SNOPowerId.Walk, x, y, Me.Z);

            return 1;
        }

        private static bool FloatPointComp(float x1, float y1, float x2, float y2)
        {
            return (x1 > x2 - 5 && x1 < x2 + 5 && y1 > y2 - 5 && y1 < y2 + 5);
        }

        public static float GetDistance(float x1, float y1, float x2, float y2)
        {
            return (float) Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
        }

        public static float GetDistance(float x2, float y2)
        {
            return (float) Math.Sqrt(Math.Pow(Me.X - x2, 2) + Math.Pow(Me.Y - y2, 2));
        }

        public static int GoTown()
        {
            if (Me.InTown)
            {
                return 0;
            }

            if (
                Me.UsePower(
                    SNOPowerId.UseStoneOfRecall))
            {
                Thread.Sleep(550);

                while (Me.Mode == UnitMode.Casting
                       ||
                       Me.Mode == UnitMode.Warping)
                {
                    Thread.Sleep(400);
                }
                return 0;
            }

            return -1;

        }
    }

}